package com.lemon.smartsafetynew.ui.adapter.record;

import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.lemon.smartsafety.R;
import com.lemon.smartsafety.listener.RecyclerTClickListener;
import com.lemon.smartsafetynew.entity.record.FunctionVo;

import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import kale.adapter.LemonRcvAdapter;
import kale.adapter.item.AdapterItem;

/**
 * Created by Andrew on 2018/1/22.
 */

public class RecordFunctionGridAdapter extends LemonRcvAdapter<FunctionVo> {

    private RecyclerTClickListener<FunctionVo> mListener;

    public RecordFunctionGridAdapter(@Nullable List<FunctionVo> data, RecyclerTClickListener<FunctionVo> listener) {
        super(data);
        this.mListener = listener;
    }


    @NonNull
    @Override
    public AdapterItem createItem(Object type) {
        return new ItemAdapter();
    }

    public class ItemAdapter implements AdapterItem<FunctionVo> {

        private FunctionVo data;
        private int mPosition;

        @Bind(R.id.icon_image)
        ImageView iconImage;
        @Bind(R.id.name_tv)
        TextView nameTv;
        @Bind(R.id.relative_layout)
        RelativeLayout relativeLayout;

        @Override
        public int getLayoutResId() {
            return R.layout.item_record;
        }

        @Override
        public void bindViews(View root) {
            ButterKnife.bind(this, root);
        }

        @Override
        public void setViews() {
            relativeLayout.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (data.getRecordFunctionEnum() != null) {
                        mListener.onItemClick(data, mPosition);
                    }
                }
            });
        }

        @Override
        public void handleData(FunctionVo functionVo, int position) {

            mPosition = position;
            data = functionVo;

            if (functionVo.getRecordFunctionEnum() != null) {
                iconImage.setImageResource(functionVo.getImage());
                nameTv.setText(functionVo.getName());
            }

        }
    }

}
